package com.xm2.demo.system.center.dao;

import com.xm2.demo.model.Center;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Create
 * @create 2018-12-12 14:49
 * @Description：
 */
@Repository
public interface CentersRepository extends JpaRepository<Center, Integer> {

    @Modifying
    @Transactional
    @Query(value = "delete from Center c where c.id in (:ids) ")
    void deleteCenterByIdIn(@Param("ids") List<Integer> ids);

    Center findCenterByCenterName(String centerName);

    @Query(nativeQuery = true, value = "select * from center as c where c.id > 0 limit :startRow,:size")
    List<Center> findAllById(@Param("startRow") Integer startRow, @Param("size") Integer size);

    @Query(value = " from Center c where c.id>0")
    List<Center> findAllCount();

    @Query(nativeQuery = true, value = "select * from center as c where c.center_name like :name% ")
    List<Center> findLikeByCenterName(@Param("name") String centerName);

    @Query(value = "select count(c.id) from Center as c where c.centerName like :name%")
    int findByCenterNameCount(@Param("name") String centerName);

    @Query(value = "select c.centerName from Center c where c.centerAddress = :address and c.id>0")
    List<String> findAddress(@Param("address") String address);
}
